

namespace IQIGame.Onigao.GamePlay
{
    public static class GameCommonUtil
    {
        public const float TimeScale = 1000;

        /// <summary>
        /// int毫秒转换成float秒
        /// </summary>
        /// <param name="time"></param>
        /// <returns></returns>
        public static float MillisecToSec(this int time)
        {
            return time / TimeScale;
        }

        /// <summary>
        /// float秒转换成int毫秒
        /// </summary>
        /// <param name="time"></param>
        /// <returns></returns>
        public static int SecToMillisec(this float time)
        {
            return (int)(time * TimeScale);
        }

        /// <summary>
        /// int厘米转换成float米
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public static float CentimetreToMetre(this int value)
        {
            return (float)value / 100;
        }

        /// <summary>
        /// 返回GameObject的Root Path
        /// </summary>
        /// <param name="fullPath"></param>
        /// <returns></returns>
        public static string GetGameObjectRootPath(string fullPath)
        {
            if (string.IsNullOrEmpty(fullPath))
            {
                return fullPath;
            }
            if (fullPath[0] == '/')
            {
                int secondSlashIndex = fullPath.IndexOf('/', 1); // 查找第二个斜杠
                if (secondSlashIndex >= 0)
                {
                    return fullPath.Substring(0, secondSlashIndex); // 返回第一个斜杠到第二个斜杠之间的部分
                }
                return fullPath;
            }
            int firstSlashIndex = fullPath.IndexOf('/'); // 查找第一个斜杠
            if (firstSlashIndex >= 0)
            {
                return fullPath.Substring(0, firstSlashIndex); // 返回第一个斜杠之前的部分
            }
            return fullPath;
        }

    }

}